namespace Ninesky.Core.Migrations
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class Initial : DbMigration
    {
        public override void Up()
        {
            DropForeignKey("dbo.Users", "RoleID", "dbo.Roles");
            DropIndex("dbo.Users", new[] { "RoleID" });
            AddColumn("dbo.Roles", "Descreption", c => c.String(nullable: false, maxLength: 200));
            DropColumn("dbo.Roles", "Description");
            DropTable("dbo.Categories");
            DropTable("dbo.CategoryGenerals");
            DropTable("dbo.CategoryLinks");
            DropTable("dbo.CategoryPages");
            DropTable("dbo.ContentTypes");
            DropTable("dbo.Users");
        }
        
        public override void Down()
        {
            CreateTable(
                "dbo.Users",
                c => new
                    {
                        UserID = c.Int(nullable: false, identity: true),
                        RoleID = c.Int(nullable: false),
                        Username = c.String(maxLength: 50),
                        Name = c.String(maxLength: 20),
                        Sex = c.Int(nullable: false),
                        Password = c.String(maxLength: 256),
                        Email = c.String(maxLength: 50),
                        LastLoginTime = c.DateTime(),
                        LastLoginIP = c.String(),
                        RegTime = c.DateTime(nullable: false),
                    })
                .PrimaryKey(t => t.UserID);
            
            CreateTable(
                "dbo.ContentTypes",
                c => new
                    {
                        ContentTypeID = c.Int(nullable: false, identity: true),
                        Name = c.String(nullable: false),
                        Controller = c.String(nullable: false),
                        Description = c.String(maxLength: 1000),
                    })
                .PrimaryKey(t => t.ContentTypeID);
            
            CreateTable(
                "dbo.CategoryPages",
                c => new
                    {
                        CategoryPageID = c.Int(nullable: false, identity: true),
                        CategoryID = c.Int(nullable: false),
                        View = c.String(nullable: false, maxLength: 255),
                    })
                .PrimaryKey(t => t.CategoryPageID);
            
            CreateTable(
                "dbo.CategoryLinks",
                c => new
                    {
                        CategoryLinkID = c.Int(nullable: false, identity: true),
                        CategoryID = c.Int(nullable: false),
                        Url = c.String(nullable: false, maxLength: 255),
                    })
                .PrimaryKey(t => t.CategoryLinkID);
            
            CreateTable(
                "dbo.CategoryGenerals",
                c => new
                    {
                        CategoryGeneralID = c.Int(nullable: false, identity: true),
                        CategoryID = c.Int(nullable: false),
                        View = c.String(nullable: false),
                        ContentTypeID = c.Int(nullable: false),
                        ContentView = c.String(),
                    })
                .PrimaryKey(t => t.CategoryGeneralID);
            
            CreateTable(
                "dbo.Categories",
                c => new
                    {
                        CategoryID = c.Int(nullable: false, identity: true),
                        Type = c.Int(nullable: false),
                        ParentID = c.Int(nullable: false),
                        ParentPath = c.String(),
                        Depth = c.Int(nullable: false),
                        Name = c.String(nullable: false, maxLength: 50),
                        Description = c.String(maxLength: 1000),
                        Order = c.Int(nullable: false),
                        Target = c.String(),
                    })
                .PrimaryKey(t => t.CategoryID);
            
            AddColumn("dbo.Roles", "Description", c => c.String(maxLength: 1000));
            DropColumn("dbo.Roles", "Descreption");
            CreateIndex("dbo.Users", "RoleID");
            AddForeignKey("dbo.Users", "RoleID", "dbo.Roles", "RoleID", cascadeDelete: true);
        }
    }
}
